/*
参数说明：
alertShow-弹出框参数{
msg-服务器提示内容
showmsg-抽奖结果弹窗提示
}
方法：
getRecodeList-取得记录list
luckGobackfn-领奖
onShow-弹窗框弹出时触发的方法
onHide-弹窗框关闭时触发的方法
*/
<template>
  <div>
    <alert v-model="alertShow.showmsg" :title="'提示'" @on-show="onShow" @on-hide="onHide">{{alertShow.msg}}</alert>
    <x-header style="background-color:#3d82e5;width:100%;position:absolute;left:0;top:0;z-index:100;" :left-options="{showBack: true}">
      <p name="content">个人中奖记录</p>
    </x-header>
     <p style="text-align: center;color: #d4081a;padding-top: 38px">只显示最近10次抽奖记录</p>
    <group  :title="''" v-for="item in recodeList">
      <cell :title="'参与日期'">
        <div slot="value">
          <h4>{{item.joinTime}}</h4>
        </div>
      </cell>
      <cell :title="'所获奖品'">
        <div slot="value">
          <h4 style="color: #418cff">{{item.name}}</h4>
        </div>
      </cell>
      <cell :title="'所获奖品'">
        <div slot="value" v-if="item.status===2">
          <p style="font-size: 10px;">已领取</p>
        </div>
        <div slot="value" v-if="item.status===1" @click="luckGobackfn(item.id)">
          <p style="font-size: 10px;display: inline-block">未领取</p>
          <p  style="font-size: 10px;color: #418cff;display: inline-block">立即领取>></p>
        </div>
      </cell>
    </group>
  </div>
</template>
<script>
  import { Group, Cell, Flexbox, FlexboxItem, Alert, XHeader } from 'vux'
  import * as urls from '../../../api/urls'
  import * as types from '../../../store/types'

  export default {
    components: {
      Group,
      Cell,
      Flexbox,
      FlexboxItem,
      Alert,
      XHeader
    },
    mounted: function () {
      this.getRecodeList()
      this.weixinfn43()
    },
    data () {
      return {
        alertShow: {
          showmsg: false,
          msg: ''
        },
        recodeList: []
      }
    },
    methods: {
      weixinfn43 () {
        let that = this
        let userId = this.$store.state.userInfo.id
        let logo = this.$store.state.empower.LOGO
        let url = window.location.origin
        let link = url + '/api/wxAuth/index?type=t1' + '&uid=' + userId
        that.$wechat.onMenuShareAppMessage({
          title: '孝行通', // 分享标题
          desc: '孝行通·微商城 一个让子女为父母尽孝的老年服务平台', // 分享描述
          link: link, // 分享链接
          imgUrl: logo, // 分享图标
          success: function () {
            // 用户确认分享后执行的回调函数
          },
          cancel: function () {
            // 用户取消分享后执行的回调函数
          }
        })
        that.$wechat.onMenuShareTimeline({
          title: '孝行通', // 分享标题
          link: link, // 分享链接
          imgUrl: logo, // 分享图标
          success: function () {
            // 用户确认分享后执行的回调函数
          },
          cancel: function () {
            // 用户取消分享后执行的回调函数
          }
        })
      },
      getRecodeList () {
        let userId = this.$store.state.userInfo.id
        let that = this
        this.http(urls.record, {userId: userId}, function (res) {
          if (res.status === 100) {
            that.recodeList = res.data.list.list
          } else {
            that.alertShow.showmsg = true
            that.alertShow.msg = res.errMsg
          }
        }, function (res) {
          that.alertShow.showmsg = true
          that.alertShow.msg = res
        })
      },
      luckGobackfn (id) {
        let that = this
        this.$store.commit(types.EMPOWER, {isPointBuy: 0})
        that.$store.commit(types.EMPOWER, {addressLuckType: true})
        that.$router.push({
          path: '/shoppingCar/SelectAddress',
          query: {
            recordId: id
          }
        })
        that.$router.go(1)
      },
      onShow () {
        // 弹窗出现时触发
      },
      onHide () {
        // 弹窗关闭时触发
      }
    }
  }
</script>
<style scoped="scoped"></style>
